<?php
// +----------------------------------------------------------------------
// | CoreThink [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.corethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com> <http://www.corethink.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Think\Controller;
/**
 * 后台默认控制器
 * @author jry <598821125@qq.com>
 */
class StockController extends AdminController{
   /* 委托记录 */
	function index()
	{
		//搜索
		$keyword = I('keyword', '', 'string');
		$condition = array('like','%'.$keyword.'%');
		$map_user['username|email|mobile'] = array($condition, $condition, $condition,'_multi'=>true);
		$userids=M('User')->where($map_user)->getField('id',true);
		$export_arr['keyword']=$keyword;
		if(!empty($userids)){
			$map['userid']=array('in',$userids);
		}else{
			$map['userid']=0;
		}
		$keyselect=I("keyselect");
		if(!empty($keyselect))
		{
			$map['status']=$keyselect;
		}
		$data_list = D('Entrust')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('id desc')->select();
        $page = new \Common\Util\Page(D('Entrust')->where($map)->count(), C('ADMIN_PAGE_ROWS'));

        $status_arr=array('0'=>'挂单','1'=>'部分成交','2'=>'成交','-1'=>'撤销');
        foreach ($data_list as $k=>$v)
        {
            $data_list[$k]['status']=$status_arr[$v['status']];
        }
        
        
        $selarr1=array(array('fieldvalue'=>'1','title'=>'委托中'),array('fieldvalue'=>'2','title'=>'未完成'),array('fieldvalue'=>'3','title'=>'已完成'));
        //使用Builder快速建立列表页面。
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('委托记录') //设置页面标题
        ->setSearch('请输入用户名/邮箱/手机号', U('index'),$selarr1,'','','1')
        ->addTableColumn('userid', '会员','function','get_username')
        ->addTableColumn('curid', '币种')
        ->addTableColumn('wtnum', '委托量')
        ->addTableColumn('cjnum', '成交量')
        ->addTableColumn('price', '单价')
        ->addTableColumn('fee', '手续费')
        ->addTableColumn('totalMoney', '总价')
        ->addTableColumn('type', '交易类型')
        ->addTableColumn('ctime', '委托时间', 'time')
		->addTableColumn('utime', '成交时间')
        ->addTableColumn('status', '状态')
        ->setTableDataList($data_list) //数据列表
        ->setTableDataPage($page->show()) //数据列表分页
        ->display();
		
	}
	function orders()
	{
		//搜索
		$keyword = I('keyword', '', 'string');
		$condition = array('like','%'.$keyword.'%');
		$map_user['username|email|mobile'] = array($condition, $condition, $condition,'_multi'=>true);
		$userids=M('User')->where($map_user)->getField('id',true);
		$export_arr['keyword']=$keyword;
		if(!empty($userids)){
			$map['userid']=array('in',$userids);
		}else{
			$map['userid']=0;
		}
		$keyselect=I("keyselect");
		if(!empty($keyselect))
		{
			$map['status']=$keyselect;
		}
		$data_list = D('Orders')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('id desc')->select();
		$page = new \Common\Util\Page(D('Orders')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
		
		$selarr1=array(array('fieldvalue'=>'1','title'=>'部分成交'),array('fieldvalue'=>'2','title'=>'成交'),array('fieldvalue'=>'-1','title'=>'撤销'),array('fieldvalue'=>'0','title'=>'挂单'));
		//使用Builder快速建立列表页面。
		$builder = new \Common\Builder\ListBuilder();
		$builder->setMetaTitle('交易记录') //设置页面标题
		->setSearch('请输入用户名/邮箱/手机号', U('orders'),$selarr1,'','','1')
		->addTableColumn('orderNo', '单号')
		->addTableColumn('userid', '委托人','function','get_username')
		->addTableColumn('curid', '币种')
		->addTableColumn('num', '总量')
		->addTableColumn('price', '单价')
		->addTableColumn('fee', '手续费')
		->addTableColumn('totalMoney', '总价')
		->addTableColumn('type', '交易类型')
		->addTableColumn('ctime', '委托时间', 'time')
		->addTableColumn('status', '状态', 'status')
		->setTableDataList($data_list) //数据列表
		->setTableDataPage($page->show()) //数据列表分页
		->display();
	}
}
